package bb.lanxing.lib.devices.bici.cmd;

import android.text.TextUtils;
//import com.umeng.analytics.pro.cc;
import bb.lanxing.lib.devices.bici.BLECommand;
import bb.lanxing.lib.devices.utils.ByteUtils;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Map;

public class FileTransCMD extends BLECommand implements Serializable {
    private static final int BICI_INFO_LENGTH = 72;
    public static final String BICI_INFO_NAME = "con";
    private static final int BICI_INFO_OLD_LENGTH_1 = 56;
    private static final int BICI_INFO_OLD_LENGTH_2 = 64;
    public static final int BODY_LENGTH = 34;
    public static final String BODY_TAIL = ".l";
    public static final byte COMMAND_ID = 11;
    public static final int HEAD_LENGTH = 60;
    public static final String HEAD_TAIL = ".h";
    public static final byte KEY_CONTENT = 5;
    public static final byte KEY_DELETE = 2;
    public static final byte KEY_DELETE_RESULT = 10;
    public static final byte KEY_GET = 1;
    public static final byte KEY_INDEX = 4;
    public static final byte KEY_NAME = 3;
    public static final byte KEY_PACKAGE_COUNT = 6;
    public static final byte KEY_REQUEST_LIST = 8;
    public static final byte KEY_RESPONSE_LIST = 9;
    public static final String LIST_NAME = "filelist";
    private static final int ONE_FILE_TITLE_LENGTH = 13;
    public static final int TYPE_BICI_INFO = 4;
    public static final int TYPE_CYCLING_BODY = 3;
    public static final int TYPE_CYCLING_HEAD = 2;
    public static final int TYPE_FILE_LIST = 1;
    private static int fileCount;
    private byte[] content;
    private String deleteName;
    private byte deleteResult;
    private short index;
    private int packageCount;
    private String transName;

    public FileTransCMD() {
        this.commandId = (byte) 11;
    }

    public FileTransCMD(byte[] bArr) {
        super(bArr);
    }

    @Override
    public void parseBody(byte[] bArr) {
        if (bArr.length < 3) {
            return;
        }
        ByteBuffer wrap = ByteBuffer.wrap(bArr);
        byte b = wrap.get();
        int i = wrap.getShort();
        byte[] bArr2 = null;
        if (bArr.length > i - 3) {
            bArr2 = new byte[(bArr.length - i) - 3];
        }
        if (b == 2) {
            byte[] bArr3 = new byte[i];
            wrap.get(bArr3);
            this.deleteName = new String(bArr3);
        } else if (b == 3) {
            byte[] bArr4 = new byte[i];
            wrap.get(bArr4);
            this.transName = new String(bArr4);
        } else if (b == 4) {
            this.index = wrap.getShort();
        } else if (b == 5) {
            byte[] bArr5 = new byte[i];
            this.content = bArr5;
            wrap.get(bArr5);
            TextUtils.isEmpty(this.transName);
        } else if (b == 6) {
            this.packageCount = wrap.getShort();
        } else if (b == 10) {
            this.deleteResult = wrap.get();
        }
        if (bArr2 == null) {
            return;
        }
        wrap.get(bArr2);
        parseBody(bArr2);
    }

    public String toString() {
        return "deleteName = " + this.deleteName + "\n transName = " + this.transName + "\n index = " + ((int) this.index) + "\n packageCount = " + this.packageCount + "\n content = " + ByteUtils.printlnByteArrayToUnsignHexString(this.content) + "\n deleteResult = " + ((int) this.deleteResult);
    }

    @Override
    protected byte[] encodeCMDBody(Map<Byte, Object> map) {
        int i;
        ByteBuffer allocate = ByteBuffer.allocate(500);
        allocate.put((byte) 11);
        allocate.put((byte) 16); //cc.n
        if (map.get((byte) 1) != null) {
            allocate.put((byte) 1);
            byte[] bArr = (byte[]) map.get((byte) 1);
            allocate.putShort((short) bArr.length);
            allocate.put(bArr);
            i = 5 + bArr.length;
        } else {
            i = 2;
        }
        if (map.get((byte) 2) != null) {
            allocate.put((byte) 2);
            byte[] bArr2 = (byte[]) map.get((byte) 2);
            allocate.putShort((short) bArr2.length);
            allocate.put(bArr2);
            i = i + 3 + bArr2.length;
        }
        if (map.get((byte) 8) != null) {
            allocate.put((byte) 8);
            allocate.putShort((short) 1);
            allocate.put(((Byte) map.get((byte) 8)).byteValue());
            i += 4;
        }
        byte[] bArr3 = new byte[i];
        allocate.flip();
        allocate.get(bArr3);
        return bArr3;
    }

    public static void clean() {
        fileCount = 0;
    }

    public byte getDeleteResult() {
        return this.deleteResult;
    }

    public void setDeleteResult(byte b) {
        this.deleteResult = b;
    }

    public String getDeleteName() {
        return this.deleteName;
    }

    public String getTransName() {
        return this.transName;
    }

    public short getIndex() {
        return this.index;
    }

    public byte[] getContent() {
        return this.content;
    }

    public int getPackageCount() {
        return this.packageCount;
    }

    public static int getFileCount() {
        return fileCount;
    }
}
